package com.my.deepseek.service.impl;

import com.my.deepseek.model.DeepSeekRequest;
import com.my.deepseek.service.DeepSeekService;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.deepseek.DeepSeekChatModel;
import org.springframework.ai.deepseek.DeepSeekChatOptions;
import org.springframework.ai.deepseek.api.DeepSeekApi;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;

/**
 * @author mars
 * @date 2025-08-31 21:38
 */
@Service
@RequiredArgsConstructor
public class DeepSeekServiceImpl implements DeepSeekService {

    private final DeepSeekChatModel chatModel;

    @Override
    public String generate(DeepSeekRequest request) {
        var prompt = new Prompt(
                request.getPrompt(),
                DeepSeekChatOptions.builder()
                        .model(DeepSeekApi.ChatModel.DEEPSEEK_CHAT.getValue())
                        .build()
        );
        return chatModel.call(prompt).getResult().getOutput().getText();
    }

    @Override
    public Flux<ChatResponse> generateStream(DeepSeekRequest request) {
        var prompt = new Prompt(
                request.getPrompt(),
                DeepSeekChatOptions.builder()
                        .model(DeepSeekApi.ChatModel.DEEPSEEK_CHAT.getValue())
                        .build()
        );
        return chatModel.stream(prompt);
    }
}
